package com.suman.bbcticker.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.suman.bbcticker.ApplicationStateObjectsHolder;
import com.suman.bbcticker.configure.RssFeedPreference;

import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

public class GoogleWeatherCustomLocationRefreshService extends Service {
	
	private static final String TAG = "GoogleWeatherCustomLocationRefreshService";

	@Override
	public void onStart(Intent intent, int startId) {	
		super.onStart(intent, startId);
		Bundle extras = intent.getExtras();
		int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
		if (extras != null) {
			mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
		}
		RssFeedPreference rssFeedPreference = ApplicationStateObjectsHolder.preferenceHashMap.get(mAppWidgetId);
		/**User has entered thier own location*/
		/**May be i need to send this data as extra?? in the intent so that i can use the same location in the auto update stuff?
		 *  */
		String postcode = rssFeedPreference.getCustomLocationWeatherSelectionValue();
		Geocoder geocoder = new Geocoder(this);
		List<Address> addressList = new ArrayList<Address>();
		try {
			addressList = geocoder.getFromLocationName(postcode, 1);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Address address = addressList.get(0);
		
		Log.e(TAG,"Country name is.." + address.getCountryName());
		
		
	}

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

}
